home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 06 General Architectures / 04 Christian / world2d.h < prev   
Encoding:
C/C++ Source or Header  |  2001-09-16  |  2.2 KB  |  105 lines

  1.  
  2.  
  3. #ifndef _World2D_H_
  4. #define _World2D_H_
  5.  
  6. #include <string>
  7.  
  8. class World2D;
  9. class WorldPos;
  10. class WorldObj;
  11.  
  12. class WorldObj
  13. {
  14.  
  15. public:
  16.  
  17.     WorldObj();
  18.  
  19.     void  setWorld ( World2D * world, char * name );           
  20.  
  21.     void  setPos   ( int x, int y );             // set the world pos center point
  22.     void  getPos   ( int & x, int & y );         // get the world pos coords
  23.  
  24.     WorldPos * getWPos () { return m_pos; }
  25.     World2D  * getWorld() { return m_world; }
  26.  
  27.     const char * getWOName  ();                  // get the object name
  28.  
  29.     void  move ();
  30.  
  31.     void  setMotionSpeed ( float speed ) 
  32.         { m_speed = speed; }
  33.  
  34.     bool  inNewPos ();
  35.  
  36.     void setDirection ( int xdir, int ydir )
  37.         { m_xdir = xdir; m_ydir = ydir; }
  38.  
  39.     void getDirection ( int &xdir, int &ydir )
  40.         { xdir = m_xdir; ydir = m_ydir; }
  41.  
  42. private:
  43.     
  44.     std::string m_name;     // object name
  45.     WorldPos *  m_pos;          
  46.     World2D  *  m_world;
  47.  
  48.     float m_lastx;          // last world x
  49.     float m_lasty;          // last world y;
  50.  
  51.     float m_speed;          // speed of movement in tile distance per second
  52.     float m_xdist;          // x distance moved across tile
  53.     float m_ydist;          // y distance
  54.  
  55.     int   m_xdir;           // x direction
  56.     int   m_ydir;           // y direction
  57. };
  58.  
  59. class WorldPos
  60. {
  61.     friend World2D;
  62.     friend WorldObj;
  63.  
  64. public:
  65.  
  66.     WorldPos();
  67.  
  68.     void       setObject ( WorldObj * obj );     // register an obj on this pos
  69.     WorldObj * getObj    ();                     // get the object on this ps
  70.  
  71. private:
  72.     int        m_id;    // world position id
  73.     WorldObj * m_obj;   // object in this position
  74.  
  75.     int m_x;    // world x
  76.     int m_y;    // world y
  77. };
  78.  
  79. class World2D
  80. {
  81.  
  82.     friend WorldObj;
  83.  
  84. public:
  85.  
  86.     World2D  ( int width, int length, float tileDist );
  87.     ~World2D ();
  88.  
  89.     WorldPos * setPos ( int x, int y, WorldObj * obj );
  90.     WorldPos * getPos ( int x, int y );
  91.  
  92.     int getWidth ()  { return m_width; }
  93.     int getLength () { return m_length; }
  94.  
  95. private:
  96.  
  97.     int   m_width;
  98.     int   m_length;
  99.  
  100.     float m_tileDist;
  101.  
  102.     WorldPos ** m_posArray;
  103. };
  104.  
  105. #endif